import { EnumSchema } from '@/utils/common/types';
import { PresetColorEnum } from '@/enums/colorEnum';
import { useI18n } from '@/hooks/web/useI18n';

/** 数据库类型枚举 */
export enum DatabaseTypeEnum {
  /** SqlServer数据库 */
  SqlServer = 100,
  /** MySql数据库 */
  MySql = 101,
  /** Oracle数据库 */
  Oracle = 102,
  /** PostgreSql数据库 */
  PostgreSql = 103,
  /** SapHana数据库 */
  SapHana = 110,
  /** Kdbndp(人大金仓)数据库 */
  Kdbndp = 150,

  /** Sqlite数据库 */
  Sqlite = 200,

  /** Azure Cosmos DB */
  Cosmos = 900,
}

/** 数据库类型实体 */
export class DatabaseTypeEntity {
  /** 数据库类型 */
  DatabaseType: DatabaseTypeEnum;
  /** 显示描述 */
  Display: string;
  /** 颜色 */
  Color?: PresetColorEnum | string;

  constructor(databaseType: DatabaseTypeEnum, color?: PresetColorEnum | string) {
    const { t } = useI18n();
    this.DatabaseType = databaseType;
    this.Color = color;
    switch (databaseType) {
      case DatabaseTypeEnum.SqlServer:
        // this.Display = 'SqlServer';
        this.Display = t('enum.databaseType.sqlServer');
        this.Color = this.Color ? this.Color : PresetColorEnum.Blue;
        break;
      case DatabaseTypeEnum.MySql:
        // this.Display = 'MySql';
        this.Display = t('enum.databaseType.mySql');
        this.Color = this.Color ? this.Color : PresetColorEnum.Cyan;
        break;
      case DatabaseTypeEnum.Oracle:
        // this.Display = 'Oracle';
        this.Display = t('enum.databaseType.oracle');
        this.Color = this.Color ? this.Color : PresetColorEnum.Geekblue;
        break;
      case DatabaseTypeEnum.PostgreSql:
        // this.Display = 'PostgreSql';
        this.Display = t('enum.databaseType.postgreSql');
        this.Color = this.Color ? this.Color : PresetColorEnum.Gold;
        break;
      case DatabaseTypeEnum.SapHana:
        // this.Display = 'SAP HANA';
        this.Display = t('enum.databaseType.sapHana');
        this.Color = this.Color ? this.Color : PresetColorEnum.Green;
        break;
      case DatabaseTypeEnum.Kdbndp:
        // this.Display = 'KingbaseES';
        this.Display = t('enum.databaseType.kdbndp');
        this.Color = this.Color ? this.Color : PresetColorEnum.Lime;
        break;
      case DatabaseTypeEnum.Sqlite:
        // this.Display = 'Sqlite';
        this.Display = t('enum.databaseType.sqlite');
        this.Color = this.Color ? this.Color : PresetColorEnum.Magenta;
        break;
      case DatabaseTypeEnum.Cosmos:
        // this.Display = 'Azure Cosmos DB';
        this.Display = t('enum.databaseType.cosmos');
        this.Color = this.Color ? this.Color : PresetColorEnum.Orange;
        break;
    }
  }
}

//#region 获取数据库类型枚举架构
/**
 * 获取数据库类型枚举架构
 */
export function getDatabaseTypeEnumSchema(enableTag = true): EnumSchema[] {
  const enumSchema: EnumSchema[] = [];
  const entities: DatabaseTypeEntity[] = [
    new DatabaseTypeEntity(DatabaseTypeEnum.SqlServer),
    new DatabaseTypeEntity(DatabaseTypeEnum.MySql),
    new DatabaseTypeEntity(DatabaseTypeEnum.Oracle),
    new DatabaseTypeEntity(DatabaseTypeEnum.PostgreSql),
    new DatabaseTypeEntity(DatabaseTypeEnum.SapHana),
    new DatabaseTypeEntity(DatabaseTypeEnum.Kdbndp),
    new DatabaseTypeEntity(DatabaseTypeEnum.Sqlite),
    new DatabaseTypeEntity(DatabaseTypeEnum.Cosmos),
  ];
  entities.forEach((item) => {
    enumSchema.push({
      key: item.DatabaseType as number,
      label: item.Display,
      value: item.DatabaseType as number,
      tag: enableTag,
      tagColor: item.Color,
    });
  });
  return enumSchema;
}
//#endregion
